home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Prograph Reference Manual.sit / Prograph Reference Manual / Prograph Reference 8-End.rsrc / TEXT_136.txt < prev    next >
Text File  |  1995-10-26  |  9KB  |  112 lines

  1.  Chapter 10    
  2.  
  3.  The Datafile Manager
  4.  
  5.  t Overview - this chapter  *471*
  6.  t Using the Datafile Manager
  7.  t Recommended Practices
  8.  t MultiUser Access to Datafile Manager
  9.  t Error Handling
  10.  t Datafile Manager Primitives Descriptions
  11.  
  12. t Overview
  13.  
  14. The Datafile Manager consists of a set of primitives that enable you to store and access data in datafiles on a disk. 
  15.  
  16. Any kind of data can be stored in datafiles, including simple data (integers, strings, booleans, and reals) or complex data (instances and lists) or External datatypes (such as handles, pictures, points, etc.).
  17.  
  18. The Datafile Manager provides both sequential access and random access to data stored in a datafile.
  19.  
  20. Datafiles created using the Datafile Manager can be accessed in query (read-only), update (single-user read/write), and share (multi-user read/write) modes. In share mode, individual clusters may be locked, preventing update by more than one user at a time.  *471*
  21.  
  22. Although the Datafile Manager is a lower level of data management system than a relational or object-oriented database manager, either of these two types of systems could be built with the Datafile Manager primitives. 
  23.  
  24. Note that the Datafile Manager primitives are listed and described at the end of this chapter. 
  25.  
  26. Components  *472*
  27.  
  28. The datafiles created by the Datafile Manager are organized into tables, clusters and keys. A datafile contains one or more tables, a table contains any number of clusters, and each table also has a set of keys used to access its clusters.
  29.  
  30. For example, a sales datafile might have three tables, one for customers, one for products and one for invoices. The customer table would have one cluster for every customer. Each customer cluster contains all the information associated with a customer; name, address, credit rating etc. Likewise for the invoice and product tables, the invoice table would have one cluster for each invoice and the product table would have one cluster for each product. All three of the tables would also have a set of keys. The customer table has a key on customer name, the product table a key on product name and the invoice table a key on invoice number. 
  31.  
  32. Datafiles  *472*
  33.  
  34. A datafile consists of one or more tables. A datafile name is not case sensitive and cannot exceed 26 characters. Two datafiles with the same name cannot be open at the same time even if they reside in separate folders or on different volumes.
  35.  
  36. A datafile has two files associated with it, one for the data and one for the keys. The name of the key file is composed of the datafile name followed by the word 窶很eys窶.
  37. A datafile is accessed in one of three modes: query, update or share.
  38.  
  39. o query mode supports fast multi-user read-only access.
  40.  
  41. o update mode enables single-user read/write access.
  42.  
  43. o share mode permits multi-user read/write access. 
  44.  
  45. Each mode has restrictions as to which operations may be performed. When using the multi-user modes, all users must be opened in the same mode.
  46.  
  47. You must open a datafile (using db-open), specifying one of the three modes, prior to accessing information in the datafile. A datafile Path Reference identifier (or datafile ID) is returned by db-open, which can then be used by other Datafile Manager primitives to identify the datafile.
  48.  
  49. Tables  *473*
  50.  
  51. A table is a collection of clusters and a set of keys. A given datafile may contain one or more tables. Each table has a unique (within the datafile) case-sensitive name (less than 127 characters). Each table may contain an unlimited number of clusters and may have an unlimited number of keys. (Note that a table must have at least one key to enable a program to step through the clusters).
  52.  
  53. You must open a table to access information in the table. Each time a table is opened, a new access path is constructed. The primitive that opened the table returns a table Path Reference identifier (or table ID) which is then used by other Datafile Manager primitives to identify that table窶冱 access path. Multiple paths can be opened on the same table.
  54.  
  55. Tables may be used to collect mixed or homomorphic (all of the same kind) sets of objects. When used in database applications, tables are usually used to store homomorphic sets of objects, such as instances of a specific class. 
  56.  
  57. If the information in a table is to be imported from or exported to a non-Prograph application, use only simple data types as the values of attributes. This will allow the table-import and table-export primitives to be used. Simple datatypes include integer, string, boolean, and real. When importing or exporting, each field may have up to 255 characters (and you should call key-first before importing).
  58.  
  59. Clusters  *473*
  60.  
  61. A cluster is an arbitrary collection of data values. In its simplest form, a cluster is the same as a record. However, a cluster is a much looser form than a traditional record - it is not necessarily of fixed length and is not restricted to being composed of fixed length fields.
  62.  
  63. Clusters can contain textual, numeric, and/or boolean (TRUE or FALSE) data, as well as External structures (e.g. PICTs and ICONs, etc.) and Prograph objects (instances of classes). (For example, a Products table could include pictures of products).
  64.  
  65. A Prograph object is converted into a cluster by the Prograph Datafile Manager primitives before it is written into a table. In turn, clusters are converted back into Prograph objects when read from a table.
  66.  
  67. Every cluster has a unique identifier called the cluster ID. (Cluster ID窶冱 are simply the byte offset of the cluster in the data file.)
  68.  
  69. Prograph objects stored in a datafile are stored in a form (data cluster) that can be rapidly converted into the equivalent Prograph object structure in memory. This form is larger than would be normally stored in a standard (text string) datafile. If the size of the datafile is an issue, use the to-string primitive to convert Prograph data into a text string, and save the string in the datafile. Use the from-string primitive to convert the text string back to a Prograph data type. This process slows down processing, but generates smaller data files.
  70.  
  71. Keys  *474*
  72.  
  73. A key is an index into a table. A key enables an application to find a specific cluster. For example, a key on customer name in the customer table would allow you to quickly find customers by name. This is commonly referred to as random access. Keys also enable an application to step through clusters in order.
  74.  
  75. Since the Datafile Manager does not assign a record number to each cluster, a programmer should create at least one key for each table, to provide a means to step through (i.e. read) the clusters. 
  76.  
  77. Each key has a name which must be unique within a table. Key names are case-sensitive and cannot exceed 127 characters.
  78.  
  79. A key must be opened in order to use it. Each time a key is opened a new access path is constructed. The primitive opening the key returns a key path reference identifier (key ID). Other datafile primitives can then use the key ID to identify any reference to that key access path. Multiple paths can be opened on the same key.
  80.  
  81. Each key path also acts as a 窶徘lace holder窶 in a table, tracking at which cluster in the table the user is positioned. You can have multiple key paths open on the same key, and thus several place holders on the same ordering.
  82.  
  83. Various options can be applied to the values stored in key fields. The following is a list of options that can be applied when creating a key. (Depending on the purpose of a key, the programmer may apply some combination of these options):
  84.  
  85. boolean          key is a boolean (TRUE or FALSE)    
  86.  
  87. integer             key is a signed integer (for example, +23, -150)    
  88.  
  89. natural          key is a 窶從atural number窶, an unsigned integer data type (for example, 
  90.                                                                                                                              79)    
  91.  
  92. real               key is a real number (for example, 2.54)    
  93.  
  94. string           key is a string (maximum 255 characters) (default)     
  95.  
  96. ascending     clusters are in accessing key order (default)    
  97.  
  98. descending   clusters are descending key order    
  99.  
  100. ascii             use the ASCII collating sequence    
  101.  
  102. native           use the native (Macintosh) collating sequence (default)    
  103.  
  104. sensitive      strings are case sensitive    
  105.  
  106. insensitive   strings are case insensitive (default)    
  107.  
  108. duplicate      multiple clusters with the same key value can exist (default)    
  109.  
  110. unique          only one cluster with a particular key value can exist    
  111.  
  112.